﻿using Appliaction.Dto.Sinv;
using Appliaction.IAppServices.Sinv;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.Sinv
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Sinv_Sale_ReturnController : ControllerBase
    {
        private readonly ISinv_Sale_ReturnService sinv_Sale_ReturnService;
        private readonly IMapper mapper;

        public Sinv_Sale_ReturnController(ISinv_Sale_ReturnService sinv_Sale_ReturnService,IMapper mapper)
        {
            this.sinv_Sale_ReturnService = sinv_Sale_ReturnService;
            this.mapper = mapper;
        }

        /// <summary>
        /// 条件查询销售退货订单
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetSinv_Sale_Return_Infos(int currentPage, int pageSize, string? customerName, string? orderCode, int orderStatus, char auditStatus)
        {
            return new JsonResult(sinv_Sale_ReturnService.GetSinv_Sale_Return_Infos(currentPage,pageSize,customerName,orderCode,orderStatus,auditStatus));
        }

        /// <summary>
        /// 条件查询销售退货订单总数
        /// </summary>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_ReturnCountAsync(string? customerName, string? orderCode, int orderStatus, char auditStatus)
        {
            return new JsonResult(await sinv_Sale_ReturnService.Sinv_Sale_ReturnCountAsync(customerName,orderCode,orderStatus,auditStatus));
        }

        /// <summary>
        /// 添加销售退货信息及其详情
        /// </summary>
        /// <param name="saleReturnWithDetailsDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Sinv_Sale_ReturnAddAsync([FromBody]SaleReturnWithDetailsDto saleReturnWithDetailsDto)
        {
            return new JsonResult(await sinv_Sale_ReturnService.Sinv_Sale_ReturnAddAsync(saleReturnWithDetailsDto));
        }

        /// <summary>
        /// 根据销售退货编号查询对应销售退货信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_ReturnByCodeAsync(string code)
        {
            return new JsonResult(await sinv_Sale_ReturnService.Sinv_Sale_ReturnByCodeAsync(code));
        }

        /// <summary>
        /// 根据销售退货编号查询对应销售退货明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> Sinv_Sale_Return_DetailsByCodeAsync(string code)
        {
            return new JsonResult(await sinv_Sale_ReturnService.Sinv_Sale_Return_DetailsByCodeAsync(code));
        }

        /// <summary>
        /// 修改销售退货信息及其详情
        /// </summary>
        /// <param name="saleReturnWithDetailsUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_ReturnUpdateAsync([FromBody] SaleReturnWithDetailsUpdateDto saleReturnWithDetailsUpdateDto)
        {
            return new JsonResult(await sinv_Sale_ReturnService.Sinv_Sale_ReturnUpdateAsync(saleReturnWithDetailsUpdateDto));
        }

        /// <summary>
        /// 修改订单审核状态、增加库存、修改销售明细退货数量、修改销售订单状态
        /// </summary>
        /// <param name="sinv_Sale_ReturnAuditUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_ReturnAuditUpdateAsync(Sinv_Sale_ReturnAuditUpdateDto sinv_Sale_ReturnAuditUpdateDto)
        {
            return new JsonResult(await sinv_Sale_ReturnService.Sinv_Sale_ReturnAuditUpdateAsync(sinv_Sale_ReturnAuditUpdateDto));
        }

        /// <summary>
        /// 逻辑删除销售退货数量并修改销售明细预计退货数量
        /// </summary>
        /// <param name="sinv_Sale_ReturnDelDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Sinv_Sale_ReturnDelAsync(Sinv_Sale_ReturnDelDto sinv_Sale_ReturnDelDto)
        {
            return new JsonResult(await sinv_Sale_ReturnService.Sinv_Sale_ReturnDelAsync(sinv_Sale_ReturnDelDto));
        }
    }
}
